/*
  具体的业务api
  这里需要登录的
*/ 

import db from './db.js'
import {conllections} from './config.js'

//添加一个类别
const _doAddType = (typename)=>{
  return db._add( conllections.recipeTypeName,{
    typename,
    status:1
  } ) //返回的是promise
}

//查询一类别 根据status:1
const _findRecipeTypeList = ()=>{
  // console.log('查询菜谱分类')
  return db._find(
      conllections.recipeTypeName,
      {
        status:1
      }
    )
}

//删除菜谱分类
const _delteById = ( id )=>{
  return db._updateById(
    conllections.recipeTypeName,
    id,
    { status:2 }
  )
}

//查询菜谱根据 用户添加的菜谱名称，是为了查看有无重复的
const _findRecipeTypeByName = ( typename )=>{
    return db._find( 
      conllections.recipeTypeName,
      {
        status:1,
        typename
      }
     )
}

//更新菜谱根据id
const _updateById = (id,data = {})=>{
  return db._updateById(
    conllections.recipeTypeName,
    id,
    data
  )
  // data = { typename:'zbcd' }
}

// 用户注册和更新功能
const _addUser = ( where = {},data={} )=>{
    return db._updateById( 
      conllections.usersName,
      where,
      data
     )
}


export default {
  _doAddType,
  _findRecipeTypeList,
  _delteById,
  _findRecipeTypeByName,
  _updateById,
  _addUser
}